﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace Articles
{
	public class FieldLengthValidator : IFormFieldValidator
	{
		public string validate(string fieldVal, string validationInfo)
		{
			int valLen = 0;
			if (int.TryParse(validationInfo, out valLen))
				if (fieldVal.Length <= valLen)
					return "Too Short";
			return null;
		}
	}

	public class EmailValidator : IFormFieldValidator
	{
		protected static Regex s_emailRegex = new Regex(@"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", RegexOptions.IgnoreCase);
		public string validate(string fieldVal, string validationInfo)
		{
			if (!s_emailRegex.Match(fieldVal).Success)
				return "Invalid email";
			return null;
		}
	}
}
